<template>
	<view class="">
		<scroll-view scroll-y="true" >
			<!-- <view>
				<view>水域(2.4分)</view>
				<view>（三十七）水域沿岸建（构）筑物保持整洁完好。(0.6 分)</view>
				<view>（三十八）各类船舶、码头保持容貌整洁(0.6 分)</view>
				<view>（三十九）水域及沿岸、滩涂容貌整洁，河堤保护区范围内无规模化家畜家禽等养殖场；有效控制“四害”密度。(0.6 分)</view>
				<view>（四十）岸边有垃圾、污水等不得直接排入水域。(0.6分)</view>
			</view> -->
			<view>
				<view>
					<view v-for="(i,index) in Imageforall" :key="Imageforall.id">
						<view @click="third(i,index)" class="border">{{i.name}}</view><br>
					</view>
				</view>
			</view>
		</scroll-view>
		
	</view>
</template>

<script>
	export default {
		data(){
			return {
				firstfirst:true,
				isstart: true,
				blist:[],
				count: 0,
				putremark: '',
				latitude: '',
				longitude: '',
				Evaluator: '',
				thisremark: true,
				isremark: true,
				ifaid: '',
				Image: '',
				igid: '',
				n:0,
				ggid:'',
				sum2:[0,0,0,0],
				showw:true,
				photoData: [],
				photoArray: [],
				canvasWidth: '',
				canvasHeight: '',
				canvasnone:'',
				photoIndex: 0,
				photoData: '',
				Imageforall:[
					{
						id:'0',
						tid:'36',
						sid:'37',
						firstfirst:true,
						first:true,
						remark: '',
						n: 0.6,
						isimage: true,
						
						name:'（三十七）水域沿岸建（构）筑物保持整洁完好。(0.6 分)',
						Image:'../../../static/th.jpg',
						fname:'点击进行拍照',
						sname:'点击重新拍照',
						scorename:'点击扣分',
						ban:true,
						score1:0,
						score2:0.1,
						score3:0.09,
						deductedscore:'已扣分',
						isdesco:false
					},
					{
						id:'1',
						tid:'37',
						sid:'38',
						firstfirst:true,
						first:true,
						remark: '',
						n: 0.6,
						isimage: true,
						
						name:'（三十八）各类船舶、码头保持容貌整洁(0.6 分)',
						Image:'../../../static/th.jpg',
						fname:'点击进行拍照',
						sname:'点击重新拍照',
						scorename:'点击扣分',
						ban:true,
						score1:0,
						score2:0.1,
						score3:0.09,
						deductedscore:'已扣分',
						isdesco:false
					},
					{
						id:'2',
						tid:'38',
						sid:'39',
						firstfirst:true,
						first:true,
						remark: '',
						n: 0.6,
						isimage: true,
						
						name:'（三十九）水域及沿岸、滩涂容貌整洁，河堤保护区范围内无规模化家畜家禽等养殖场；有效控制“四害”密度。(0.6 分)',
						Image:'../../../static/th.jpg',
						fname:'点击进行拍照',
						sname:'点击重新拍照',
						scorename:'点击扣分',
						ban:true,
						score1:0,
						score2:0.1,
						score3:0.09,
						deductedscore:'已扣分',
						isdesco:false
					},
					{
						id:'3',
						tid:'39',
						sid:'40',
						firstfirst:true,
						first:true,
						remark: '',
						n: 0.6,
						isimage: true,
						
						name:'（四十）岸边有垃圾、污水等不得直接排入水域。(0.6分)',
						Image:'../../../static/th.jpg',
						fname:'点击进行拍照',
						sname:'点击重新拍照',
						scorename:'点击扣分',
						ban:true,
						score1:0,
						score2:0.1,
						score3:0.09,
						deductedscore:'已扣分',
						isdesco:false
					}
				]
			}
		},
		onLoad() {
			
			// var clear = uni.clearStorage()
			console.log(this.blist)
			console.log('清楚了')
		},
		methods:{
			third(e){
				console.log(e)
				uni.navigateTo({
					url:'../twotown/' + e.sid,
					success:()=> {
						console.log('跳到了',e.sid)
					}
				})
			},
			getTime() {
				var date = new Date(),
					year = date.getFullYear(),
					month = date.getMonth() + 1,
					day = date.getDate(),
					hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(),
					minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(),
					second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
				month >= 1 && month <= 9 ? (month = "0" + month) : "";
				day >= 0 && day <= 9 ? (day = "0" + day) : "";
				var timer = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
				return timer;
			},
			canceldeducted(e, b) {
				uni.showModal({
					title: '提示',
					content: '是否对该项取消扣分',
					success: res => {
						var that = this
						if (res.confirm) {
							console.log('用户点击确定');
							console.log('vuex啊啊啊啊',that.$store.state.value)
							that.Imageforall[e.id].Imageall[b].isdscorename = false
							that.Imageforall[e.id].Imageall[b].isscorename = true
							that.Imageforall[e.id].Imageall[b].ban = true
							that.Imageforall[e.id].Imageall[b].Image = '../../../static/th.jpg'
							if (that.$store.state.value == 'A' || that.$store.state.value == 'B') {
								that.Imageforall[e.id].score1 = that.Imageforall[e.id].score1 + 0.12
								that.$store.state.alltownscore[e.tid] = that.Imageforall[e.id].score1
								that.count -= 1
								console.log(that.Imageforall[e.id].score1)
							} else if (that.$store.state.value == 'C' || that.$store.state.value == 'D' || that.$store.state.value == 'E') {
								that.Imageforall[e.id].score1 = that.Imageforall[e.id].score1 + 0.1
								that.Imageforall[e.id].score1 = that.Imageforall[e.id].score1.toFixed(1)
								that.Imageforall[e.id].score1 = parseFloat(that.Imageforall[e.id].score1)
								that.$store.state.alltownscore[e.tid] = that.Imageforall[e.id].score1
								that.count -= 1
								console.log(that.Imageforall[e.id].score1)
							} else {
									console.log('第三类考评')
							}
			
							if (that.Imageforall[e.id].score1 == 0) {
								that.Imageforall[e.id].isdesco = false
								that.Imageforall[e.id].isscore1 = false
							}
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})
				console.log(e.id)
				console.log(b)
				console.log(this.Imageforall)
			},
			deducted(e, b) {
				var that = this
				if(that.$store.state.value == 'C' || that.$store.state.value == 'D' || that.$store.state.value == 'E'){
					if (this.count > 5) {
						uni.showModal({
							title: '提示',
							content: '该指标已达到扣分上限',
							success: res => {
								if (res.confirm) {
									console.log('用户点击确定');
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						})
					} else {
						that.Imageforall[e.id].Imageall[b].isdscorename = true
						that.Imageforall[e.id].Imageall[b].isscorename = false
						console.log(e)
						console.log(b)
						that.ifaid = e.id
						that.iaid = b
						that.Imageforall[e.id].isdesco = true
						that.Imageforall[e.id].isscore1 = true
						that.Imageforall[e.id].Imageall[b].ban = false
						if (that.$store.state.value == 'A' || that.$store.state.value == 'B') {
							that.Imageforall[e.id].score1 = that.Imageforall[e.id].score1 - 0.12
							that.$store.state.alltownscore[e.tid] = that.Imageforall[e.id].score1
							console.log(that.Imageforall[e.id].score1)
						} else if (that.$store.state.value == 'C' || that.$store.state.value == 'D' || that.$store.state.value == 'E') {
							that.Imageforall[e.id].score1 = that.Imageforall[e.id].score1 - 0.1
							that.Imageforall[e.id].score1 = that.Imageforall[e.id].score1.toFixed(1)
							that.Imageforall[e.id].score1 = parseFloat(that.Imageforall[e.id].score1)
							that.$store.state.alltownscore[e.tid] = that.Imageforall[e.id].score1
							console.log(that.Imageforall[e.id].score1)
						} else {
							console.log('第三类考评')
						}
						// this.Imageforall[e.id].score1 = this.Imageforall[e.id].score1 - 0.12
						that.sum2[e.id] = that.Imageforall[e.id].score1
						that.count += 1
						console.log('我用咖啡拉花拉出一跳白色的线，举一杯眷恋',that.$store.state.alltownscore)
						console.log(that.count)
						console.log('-------------------')
						console.log(that.sum2)
						console.log(that.Imageforall)
					}
				}
				if(that.$store.state.value == 'A' || that.$store.state.value == 'B'){
					if (this.count > 4) {
						uni.showModal({
							title: '提示',
							content: '该指标已达到扣分上限',
							success: res => {
								if (res.confirm) {
									console.log('用户点击确定');
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						})
					}else {
						that.Imageforall[e.id].Imageall[b].isdscorename = true
						that.Imageforall[e.id].Imageall[b].isscorename = false
						console.log(e)
						console.log(b)
						that.ifaid = e.id
						that.iaid = b
						that.Imageforall[e.id].isdesco = true
						that.Imageforall[e.id].isscore1 = true
						that.Imageforall[e.id].Imageall[b].ban = false
						if (that.$store.state.value == 'A' || that.$store.state.value == 'B') {
							that.Imageforall[e.id].score1 = that.Imageforall[e.id].score1 - 0.12
							that.$store.state.alltownscore[e.tid] = that.Imageforall[e.id].score1
							console.log(that.Imageforall[e.id].score1)
						} else if (that.$store.state.value == 'C' || that.$store.state.value == 'D' || that.$store.state.value == 'E') {
							that.Imageforall[e.id].score1 = that.Imageforall[e.id].score1 - 0.1
							that.Imageforall[e.id].score1 = that.Imageforall[e.id].score1.toFixed(1)
							that.Imageforall[e.id].score1 = parseFloat(that.Imageforall[e.id].score1)
							that.$store.state.alltownscore[e.tid] = that.Imageforall[e.id].score1
							console.log(that.Imageforall[e.id].score1)
						} else {
							console.log('第三类考评')
						}
						// this.Imageforall[e.id].score1 = this.Imageforall[e.id].score1 - 0.12
						that.sum2[e.id] = that.Imageforall[e.id].score1
						that.count += 1
						console.log('我用咖啡拉花拉出一跳白色的线，举一杯眷恋',that.$store.state.alltownscore)
						console.log(that.count)
						console.log('-------------------')
						console.log(that.sum2)
						console.log(that.Imageforall)
					}
				}
			},
			addpicture(e, b) {
				uni.chooseImage({
					count: 1,
					sourceType: ['camera'],
					success: (res) => {
						console.log(res)
						console.log(e)
						console.log(e.Imageall[e.id].id)
						this.ggid = e.id
						this.ifaid = e.id
						this.iaid = b
						this.showw = true
						this.Imageforall[this.ifaid].Imageall[this.iaid].Image = res.tempFilePaths[0]
						console.log(res.tempFilePaths[0])
						uni.getLocation({
							type: 'wgs84',
							geocode: true,
							success: (res) => {
								console.log(res)
								this.latitude = res.latitude
								this.longitude = res.longitude
								console.log(this.latitude)
								console.log(this.longitude)
								this.beforeAddWaterMart();
							},
							fail: function() {
								uni.showToast({
									title: '获取地址失败,请检查网络连接',
									icon: 'none'
								});
							}
						})
						// this.beforeAddWaterMart();
					}
				})
			},
			beforeAddWaterMart() {
				console.log('用了')
				this.addWaterMark(() => {
					if (this.photoIndex < this.photoArray.length - 1) {
						this.photoIndex++;
						this.beforeAddWaterMart()
					} else {
						uni.hideLoading()
					}
				})
			},
			addWaterMark(callback) {
				uni.showLoading({
					title: '正在加载中...',
					mask: true
				})
				console.log('用了')
				setTimeout(() => {
					uni.getImageInfo({
						src: this.Imageforall[this.ifaid].Imageall[this.iaid].Image,
						success: res => {
							console.log(res)
							this.time = this.getTime();
							if(this.canvasHeight != res.height || this.canvasWidth != res.width){
								this.canvasWidth = res.width + 'px'
								this.canvasHeight = res.height + 'px'
							} else {
								this.canvasWidth = res.width + 'px'
								this.canvasHeight = res.height + 'px'
							}
							var ctx = uni.createCanvasContext('myCanvas');
							ctx.drawImage(this.Imageforall[this.ifaid].Imageall[this.iaid].Image, 0, 0,res.width,res.height);
							// ctx.translate(res.width / 2, res.height / 2);
							ctx.beginPath();
							ctx.setFontSize(40);
							ctx.setFillStyle("white");
							ctx.fillText(this.time, 0, 1380);
							ctx.fillText('纬度:' + this.latitude + '  ' + '经度:' + this.longitude, 0, 1420)
							ctx.draw(false, () => {
								console.log('用了')
								setTimeout(() => {
									console.log("asdf")
									uni.canvasToTempFilePath({
										canvasId: "myCanvas",
										success: res => {
											console.log(res.tempFilePath)
											// this.Imageforall[this.ifaid].Imageall[this
											// 	.iaid].Image = res.tempFilePath;
											this.showw = false
											this.tempFilePath = res.tempFilePath
											// var formData = new FormData();
											//     formData.append('file', this.tempFilePath);
											console.log(this.Imageforall)
											uni.saveImageToPhotosAlbum({
												filePath: res.tempFilePath,
												success: (res) => {
													this.Imageforall[this.ifaid].Imageall[this.iaid].Image = res.path;
													console.log(res)
													// uni.uploadFile({
													// 	url: 'http://192.168.0.37:8000/kaoping/evidence/image/',
													// 	filePath: this.Imageforall[this.ifaid].Imageall[this.iaid].Image,
													// 	name: 'image',
													// 	success: res => {
													// 		uni.showToast({
													// 			title: "保存成功",
													// 			icon: "none"
													// 		});
													// 		setTimeout
													// 			(() => {
													// 					uni.hideLoading()
													// 				},
													// 				2000
													// 				)
													// 		console.log('错误')
													// 		console.log(res)
													// 		console.log(this.Imageforall[this.ifaid].Imageall[this.iaid].Image)
													// 	}
													// })
													if(this.Imageforall[this.ifaid].first){
														this.Imageforall[this.ifaid].first = false
														var sa = {
															name:this.Imageforall[this.ifaid].name,
															Imageall:[
																{
																	Image:this.Imageforall[this.ifaid].Imageall[this.iaid].Image,
																}
															]
														}
														this.blist.push(sa)
														var set = new Set(this.blist)
														var thisset = [...set]
														this.alllist = thisset
														console.log('巴士克特波',this.alllist)
														if(this.firstfirst){
															this.Imageforall[this.ifaid].firstfirst = false
															// this.$store.state.decifm.push(...this.blist)
														} else {
															// this.$store.state.decifm.push(...sa)
														}
															console.log(this.$store.state.decifm)
													} else {
														var ta = {
															Image:this.Imageforall[this.ifaid].Imageall[this.iaid].Image
														}
														this.blist[this.ifaid].Imageall.push(ta)
														console.log(ta)
														// this.$store.state.decifm[this.ifaid].Imageall.push(ta)
														console.log(this.$store.state.decifm)
														var set = new Set(this.blist)
														var thisset = [...set]
														this.alllist = thisset
														console.log('巴士克特波',this.alllist)
													}
													console.log(this.Imageforall[this.ifaid].first)
													console.log('它来了它来了',this.blist)
													// console.log(this.$store.state.decifm)
													uni.setStorage({
														key: 'img',
														data: this.Imageforall,
														success: (res) => {
															console.log('成功了')
															console.log(res)
															console.log(this.Imageforall)
														}
													})
													uni.showToast({
														title: "保存成功",
														icon: "none"
													});
												},
												fail: err => {
													console.log(err)
													uni.showToast({
														title: "保存失败，请稍后重试",
														icon: "none"
													});
												}
											});
											uni.showToast({
												title: '加载成功',
												icon: 'success',
												duration: 2000
											})
											callback();
											console.log('用完了')
										}
									})
								}, 500)
							});
						},
						fail: function() {
							uni.showToast({
								title: '获取图片失败',
								icon: 'none'
							});
						}
					})
				},500)
				
			},
			checkimg(e, b) {
				console.log(e)
				console.log(b)
				uni.previewImage({
					urls: [this.Imageforall[e.id].Imageall[b].Image],
					success: (res) => {
						console.log(this.Imageforall[e.id].Imageall[b].Image)
					},
					fail: function() {
						uni.showToast({
							title: '网络错误,请检查网络连接',
							icon: 'none'
						});
					}
				})
			},
			submit() {
				this.$store.state.decifm.push(...this.alllist)
				var thedec = new Set(this.$store.state.decifm)
				var truedec = [...thedec]
				this.$store.state.decifm = truedec
				uni.showToast({
					title:'保存成功'
				})
				uni.setStorage({
					key:'img11',
					data:this.Imageforall,
					success:res => {
						console.log('成功了')
						console.log(res)
						console.log(this.$store.state.decifm)
					}
				})
				// uni.request({
				// 	url: 'http://192.168.0.37:8000/kaoping/excelfile/',
				// 	method: 'POST',
				// 	data: {
				// 		name: 'sad',
				// 		score_list: this.sum2,
				// 		category: '123',
				// 		position: '2222'
				// 	},
				// 	success: res => {
				// 		console.log('传好了')
				// 		console.log(res)
				// 	}
				// })
			}
		}
	}
</script>

<style scoped>
	.picbtn {
		/* float: left; */
		font-size: 20rpx;
		width: 100rpx;
		height: 50rpx;
		background-color: pink;
		margin-left: 20rpx;
		margin-top: 10rpx;
	}
	
	.bottom-btn {
		position: fixed;
		margin-top: 20rpx;
		width: 100%;
		bottom: 0rpx;
	}
	
	.bmbtn {
		background-color: skyblue;
		color: whitesmoke;
	}
	
	.bmbtn:active {
		background-color: deepskyblue;
	}
	
	.remark {
		width: 750rpx;
		height: 200rpx;
		background-color: pink;
	}
	
	.scorebtn {
		font-size: 20rpx;
		/* margin-top: -50rpx; */
		width: 100rpx;
		height: 50rpx;
		margin-top: 15rpx;
		margin-left: 20rpx;
		/* margin-left: 450rpx; */
		/* background-color: pink; */
	}
	
	.btn {
		float: left;
		/* margin-top: 150rpx; */
	}
	
	.border {
		width: 750rpx;
		background-color: #F8F8FF;
		border: 2px solid skyblue;
		margin-top: 15rpx;
		margin-bottom: 35rpx;
		text-align: center;
	}
	.border:active {
		background-color: deepskyblue;
	}
	.desco {
		float: right;
		width: 115rpx;
		height: 115rpx;
		line-height: 110rpx;
		text-align: center;
		/* margin-left: 600rpx; */
		margin-right: 25rpx;
		margin-top: 15rpx;
		border-radius: 50%;
		border: 1px solid red;
		/* background-color: red; */
		color: red;
	}
	.scoref {
		float: right;
		/* margin-left: 300rpx; */
		margin-right: 20rpx;
		margin-top: -50rpx;
		color: red;
	}
</style>